<template>
    <div>
       <div style="height:50px"></div>
       <van-pull-refresh
        v-model="loading"
        success-text="刷新成功"
        @refresh="onRefresh"
        >
        <div
        class="cards"
        v-for="item in list"
        :key="item.i"
        >
            <van-card
            :thumb='item.img_url'
            @click="news(item.id)"
            >
                <div slot="title" style='border:0;'><br>
                    <div plain type="danger" style="fontSize:14px;color:#000;fontWeight:700;">{{item.title}}</div><br><br>
                    <div plain type="danger" style="fontSize:12px;color:#226AFF;paddingTop:10px;">发表时间：{{item.add_time.substring(0,10)}}</div>
                    <div plain type="danger" style="color:#969799;fontWeight:700;paddingTop:10px;float:right;">点击：{{item.click}}</div>
                </div>
            </van-card>
        </div>
        </van-pull-refresh>
        <div style="height:50px"></div>
    </div>
</template>
<script>
export default {
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false
    }
  },
  created () {
    this.getList()
  },
  methods: {
    onLoad () {
      setTimeout(() => {
        if (this.refreshing) {
          this.list = []
          this.refreshing = false
        }

        for (let i = 0; i < 0; i++) {
          this.list.push(this.list.length + 1)
        }
        this.loading = false

        if (this.list.length >= 40) {
          this.finished = true
        }
      }, 1000)
    },
    onRefresh () {
      // 清空列表数据
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    },
    async getList () {
      const { data: res } = await this.$axios.get('http://www.liulongbin.top:3005/api/getnewslist')
      console.log(res)
      if (res.status !== 0) return this.$message.error('无法获取数据！')
      console.log(res.message)
      this.list = res.message
      console.log(this.list)
    },
    news (e) {
      console.log(e)
      this.$router.push(
        {
          path: '/details/' + e
        })
    }
  }
}
</script>

<style scoped lang="less">
div van-card {
  border-bottom: 1px solid #ccc;
}
</style>
